﻿using System;
using System.Text;
using System.Web.SessionState;
using System.Web.UI.WebControls;

using UI.WebPage.PageBase;
using UI.WebControls;
using Tools.Msn.China;
namespace UI.WebPage.Background
{
    /// <summary>
    /// UI层，后台添加信息的页面基类
    /// </summary>
    public class AddInfoPage : AuthModelPageBase, IRequiresSessionState
    {
        public string Message = string.Empty;

        /// <summary>
        /// 获取参数id
        /// </summary>
        /// <returns></returns>
        public int GetUpdateID()
        {
            return this.GetUpdateID("id");
        }
        /// <summary>
        /// 获取url参数id
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int GetUpdateID(string param)
        {
            int result = 0;
            int.TryParse(base.GetQueryString(param), out result);
            return result;
        }

        /// <summary>
        /// 设置CKFinder的文件根路径
        /// </summary>
        /// <param name="directory">目录</param>
        public void SetCKFinder(string directory)
        {
            CookieManager.SetCookie("finderpath", directory);
        }

        /// <summary>
        /// 设置CKFinder的文件根路径，同时整合ckeditor编辑器
        /// </summary>
        /// <param name="directory">目录</param>
        /// <param name="ckeditor">CKEditor对象</param>
        public void SetCKFinder(string directory, object ckeditor)
        {
            CookieManager.SetCookie("finderpath", directory);
            CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser();
            _FileBrowser.BasePath = "/ckfinder/";
            _FileBrowser.SetupCKEditor(ckeditor);
        }

        /// <summary>
        /// 获取排除过滤字后的参数字典
        /// </summary>
        /// <param name="filterKey"></param>
        /// <returns></returns>
        public string GetQueryStringAdd(string filterKey)
        {
            StringBuilder repo = new StringBuilder();
            foreach (string key in QueryString.Keys)
                if (!key.Equals(filterKey))
                    repo.AppendFormat("&{0}={1}", key, QueryString[key]);
            return repo.ToString();
        }

        /// <summary>
        /// 默认排除id参数的参数列表
        /// </summary>
        /// <returns></returns>
        public string GetQueryStringAdd()
        {
            return this.GetQueryStringAdd("id");
        }

        /// <summary>
        /// 初始化预发布状态
        /// </summary>
        /// <param name="txtOnline">预发布日期</param>
        /// <param name="ddlHour">预发布小时</param>
        /// <param name="ddlMiniute">预发布分钟</param>
        public void InitOnlineStatus(TextBox txtOnline, TimeHour ddlHour, TimeMinute ddlMiniute)
        {
            DateTime now = DateTime.Now;
            txtOnline.Text = now.ToString("yyyy-MM-dd");
            ddlHour.DefaultSelect = now.ToString("HH");
            ddlMiniute.DefaultSelect = now.ToString("mm");
        }
    }
}
